<!--
  政策库 - 发布审核 - 审核
-->
<template>
  <div class="policy-review" style="overflow:auto">
    <AppMainContent style="width:100%;margin-top:0px;margin-left:0px;">
      <el-row style="background-color:#fff">
        <el-col :span="2" style="float:right;margin-bottom:10px;margin-top:8px">
          <el-button type="primary" @click="pass" style="width:100px">
            审核通过
          </el-button>
        </el-col>
        <el-col :span="2" style="float:right;margin-bottom:8px;margin-top:8px">
          <el-button type="warning" @click="sandBack" style="width:100px">
            退回
          </el-button>
        </el-col>
      </el-row>
    </AppMainContent>
    <AppMainContent>
      <!-- 卡片头部 -->
      <el-card>
        <CardFormTitle title="政策信息" />
        <!-- 表单内容 -->
        <CardFormContent style="width:1000px;height:390px;">
          <div style="width:1400px">
            <div class="addNav">
              <span>政策标题</span>
              <br />
              <el-input
                v-model="formInline.title"
                style="width:460px"
                :disabled="true"
              ></el-input>
            </div>
            <div class="addNav">
              <span>政策级别</span>
              <br />
              <el-input
                v-model="formInline.levelDesc"
                :disabled="true"
              ></el-input>
            </div>

            <div class="addNav">
              <span style="margin-right:230px">政策类型</span>
              <br />
              <el-input
                v-model="formInline.typeDesc"
                :disabled="true"
              ></el-input>
            </div>
          </div>
          <div class="addNavSecond">
            <span>政策来源</span>
            <br />
            <el-input v-model="formInline.source" :disabled="true"></el-input>
          </div>
          <div class="addNavThird">
            <span style="margin-left:35px">政策发布时间</span>
            <br />
            <el-date-picker
              type="date"
              v-model="formInline.awardTime"
              style="margin-left:35px"
              :disabled="true"
            ></el-date-picker>
          </div>

          <div class="died">
            <span>新增人</span>
            <br />
            <el-input
              v-model="formInline.createUserName"
              :disabled="true"
            ></el-input>
          </div>

          <div class="diedtwo">
            <span>新增时间</span>
            <br />
            <el-date-picker
              type="date"
              v-model="formInline.publishTime"
              :disabled="true"
            ></el-date-picker>
          </div>

          <div class="vueEditor">
            <div
              style="font-size:16px;font-weight:bold;margin-bottom:5px;display:none"
            >
              富文本编辑器内容：{{ formInline.info }}
            </div>
            <VueQuillEditor
              :content.sync="formInline.info"
              :business-type="1"
              :disabled="true"
            />
          </div>
        </CardFormContent>

        <!-- 审核信息 -->
        <CardFormTitle title="审核信息" />
        <div style="width:600px;margin-top:-20px">
          <div class="comefirst">
            <span style="font-weight: bold;font-size: 15px;">审核人</span>
            <br />
            <el-input
              :value="auditInfo.examineUserName"
              style="width:200px"
              :disabled="true"
            ></el-input>
          </div>
          <div class="shenhebeizhu" style="margin-top:10px">
            <span style="font-weight: bold;font-size: 15px;">
              审核备注
            </span>
            <el-input
              type="textarea"
              v-model="auditInfo.examineOpinion"
              show-word-limit
              style="width: 105%;"
              placeholder="请输入原因"
            />
          </div>
        </div>
      </el-card>
    </AppMainContent>
  </div>
</template>

<script>
//审核请求
import { aduitPolicy, getAuditPolicyInfo } from '@/api/policy/audit/index'
export default {
  name: 'PolicyReviewAdd',
  data() {
    return {
      formInline: {
        levelDesc: '',
        typeDesc: '',
      },
      auditInfo: {
        id: '',
        examineUserId: '',
        examineUserName: '',
        examineTime: '',
        examineOpinion: '',
        examineResult: '',
        status: '',
      },
    }
  },
  methods: {
    pass() {
      let _this = this
      _this.auditInfo.examineUserId = this.$store.state.user.userInfo.id
      _this.auditInfo.examineOpinion = this.auditInfo.examineOpinion
      _this.auditInfo.examineResult = 1
      _this.auditInfo.status = 4
      if (_this.auditInfo.examineOpinion === '') {
        this.$alert('审核信息内容不能为空 ', ' 此项必填', {
          dangerouslyUseHTMLString: true,
        })
      } else {
        this.$confirm('确认通过该政策发布？, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then(() => {
            return aduitPolicy(_this.auditInfo)
          })
          .then(() => {
            this.msgSuccess('审核通过成功')
            window.location.href = '/policy/review'
          })
          .catch(() => {
            this.$message('已取消审核')
          })
      }
    },
    sandBack() {
      let _this = this
      _this.auditInfo.examineUserId = this.$store.state.user.userInfo.id
      _this.auditInfo.examineOpinion = this.auditInfo.examineOpinion
      _this.auditInfo.examineResult = 2
      _this.auditInfo.status = 3
      if (_this.auditInfo.examineOpinion === '') {
        this.$alert('审核信息内容不能为空 ', ' 此项必填', {
          dangerouslyUseHTMLString: true,
        })
      } else {
        this.$confirm('是否 退回 该政策发布？, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then(() => {
            return aduitPolicy(_this.auditInfo)
          })
          .then(() => {
            this.msgSuccess('审核已退回')
            window.location.href = '/policy/review'
          })
          .catch(() => {
            this.$message('已取消审核')
          })
      }
    },
    //* 处理当前时间
    addDate() {
      const nowDate = new Date()
      const date = {
        year: nowDate.getFullYear(),
        month: nowDate.getMonth() + 1,
        date: nowDate.getDate(),
        hour: nowDate.getHours(),
        mf:
          nowDate.getMinutes() < 10
            ? '0' + nowDate.getMinutes()
            : nowDate.getMinutes(),
      }
      const newmonth = date.month > 10 ? date.month : '0' + date.month
      const day = date.date > 10 ? date.date : '0' + date.date
      this.auditInfo.examineTime =
        date.year + '-' + newmonth + '-' + day + ' ' + date.hour + ':' + date.mf
    },
    changeInfo() {
      let id = this.$route.query.id
      getAuditPolicyInfo(id).then((response) => {
        if (response.data != null && response.code === 200) {
          this.formInline = response.data
          this.auditInfo.id = response.data.id
          this.formInline.levelDesc = response.data.level.desc
          this.formInline.typeDesc = response.data.type.desc
        }
      })
    },
  },
  mounted() {
    this.auditInfo.examineUserName = this.$store.state.user.userInfo.userName
    this.addDate()
    this.changeInfo()
  },
  watch: {
    $route(to, from) {
      this.changeInfo()
    },
  },
}
</script>

<style lang="scss"  scoped>
.addNav {
  float: left;
  margin-left: 20px;
  margin-right: 20px;
  margin-top: -15px;
}

.addNav > span {
  margin-bottom: -10px;
  display: block;
  font-weight: bold;
  font-size: 15px;
}
.addNavSecond {
  float: left;
  margin-left: 20px;
  margin-right: 10px;
  margin-top: 20px;
}

.addNavSecond > span {
  margin-bottom: -10px;
  display: block;
  font-weight: bold;
  font-size: 15px;
}

.addNavThird {
  float: left;
  margin-left: -10px;
  margin-right: 10px;
  margin-top: 20px;
}

.addNavThird > span {
  margin-bottom: -10px;
  margin-left: 19px;
  display: block;
  font-weight: bold;
  font-size: 15px;
}

.vueEditor {
  float: left;
  margin-top: 13px;
  margin-left: 20px;
}

.died {
  float: left;
  margin-left: 35px;
  margin-top: 20px;
}

.died > span {
  margin-bottom: -10px;
  display: block;
  font-weight: bold;
  font-size: 15px;
}

.diedtwo {
  float: left;
  margin-left: 55px;
  margin-top: 20px;
}

.diedtwo > span {
  margin-bottom: -10px;
  display: block;
  font-weight: bold;
  font-size: 15px;
}
</style>
